package com.code.google.ccengel.android.CardsAlpha.model;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.code.google.ccengel.android.CardsAlpha.model.Rank;


public class Deck {
	/**
	 * Constructs a new deck.
	 */
	public Deck(DeckType type) {
		this.shuffledDeck = newDeck(type);
	}

	/**
	 * Creates a new deck.
	 * 
	 * @return shuffledDeck
	 */
	public static List<Card> newDeck(DeckType type) {
		List<Card> sortedDeck = new ArrayList<Card>();
		if (type.equals(DeckType.NORMAL)) {
			for (Suit suit : Suit.values())
				for (Rank rank : Rank.values())
					sortedDeck.add(new Card(rank, suit));

			return shuffle(sortedDeck);
		}
		if (type.equals(DeckType.EUCHRE)) {
			for (Suit suit : Suit.values())
				for (EuchreRank rank : EuchreRank.values())
					sortedDeck.add(new Card(rank, suit));

			return shuffle(sortedDeck);
		}
		return null;

	}

	/**
	 * Shuffles the deck.
	 * 
	 * @param sortedDeck
	 *            an unshuffled deck
	 * @return Shuffled deck of cards
	 */
	public static List<Card> shuffle(List<Card> inDeck) {
		Collections.shuffle(inDeck);
		Collections.shuffle(inDeck);
		Collections.shuffle(inDeck);

		return inDeck;
	}

	/**
	 * Gets the number of cards in the deck.
	 * 
	 * @return
	 */
	public int numCards() {

		return shuffledDeck.size();
	}

	/**
	 * Draws a card from the deck
	 * 
	 * @return card
	 */
	public Card Draw() {
		if (!shuffledDeck.isEmpty()) {
			Card newCard = shuffledDeck.get(0);
			shuffledDeck.remove(0);
			return newCard;
		}
		return null;
	}

	private List<Card> shuffledDeck = new ArrayList<Card>();

	
}
